// component/visitorsAll/com/visitor-analyze-item/visitor-analyze-item.js
import util from '../../../../utils/util.js'

const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
      type: Object,
      value: {}
    }
  },

  options: {
    styleIsolation: 'apply-shared',
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    _info: {}
  },

  observers: {
    info() {
      let info = {...this.data.info}
      info.title = info.title2 || info.title || ''
      try {
        info.isMe = info.unionid === app.globalData.sessionUser.extProps.wechatUnionid
      } catch (error) {}

      if (info.sign == "newHouse") {
        info.title = info.title + ' (新房)'
        info.imgId = info.first_picture_url
        info.detailInfo = `${info.average_price ? '均价' + info.average_price + '元/㎡' : '未填均价'}`
        this.setData({
          _info: info
        })
        return
      }
      let titlesList = info.title.split("  ")
      info.title = titlesList[0]
      
      info.detailInfo = `
        ${info.total_prices && info.total_prices!=-1? (info.total_prices>=10000 ? info.total_prices/10000 + '万' : info.total_prices + '元'):'未填价格'}
        ${titlesList[1] || ""}
        ${info.build_size && info.build_size!=-1?info.build_size + '㎡':'未填面积'}
      `
      // info._totalPrices = `${info.totalPrices && info.totalPrices!=-1? (info.totalPrices>=10000 ? info.totalPrices/10000 + '万' : info.totalPrices + '元'):'未填价格'}`;
      // info._houseType = `${info.room || 0}室${info.hall || 0}厅${info.toilet || 0}卫`;
      // info._area = `${info.buildSize && info.buildSize!=-1?info.buildSize + '㎡':'未填面积'}`
      info._houseImg = `${info.imgId && info.imgId != util.ImagesUrl + 'null' ? info.imgId : '/images/defaultImgSmall.jpg'}`
      this.setData({
        _info: info
      })
    }
  },

  attached(){
    const that = this;
    that.setData({
      url: util.ImagesUrl
    })
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleGoToCustomer() {
      wx.navigateTo({ url: `/pages/customerDetailInfo/customerDetailInfo?userId=${this.data.info.anUserId}&unionid=${this.data.info.unionid}` })
    },
    hanldeCopyNickname() {
      this.triggerEvent("copyNickname", this.data.info)
    },
    handleGoRentalHouseDetail() {
      const houdelid = this.data.info.houDelId;
      const houseTypes = this.data.info.housetype;
      if (this.data.info.deleted) {
        wx.showToast({
          icon: 'none',
          title: '该房源被删除，无法查看',
        })
        return
      }
      if (this.data.info.sign == "newHouse") {
        wx.navigateTo({
          url: `/pages/newBuildinghouse/newRentalHouseDetail/newRentalHouseDetail?houdelid=${this.data.info.id}&isMay=true`
        })
      } else {
        wx.navigateTo({
          url: '/pages/house/RentalHouseDetail/RentalHouseDetail?houdelid=' + houdelid + "&from=1" + "&type=" + houseTypes,
        })
      }
    },
    hanldeSetTop(e) {
      this.triggerEvent("onSetTop", {
        target: this.data._info.anUserId,
        status: this.data._info.topStatue
      })
    },

    onHideMe() {
      this.triggerEvent("hideMe", {
        userId: this.data._info.anUserId,
        unionid: this.data._info.unionid,
        target: 'MANAGE'
      })
    }



  }
})